Repository navigation
feat(pm-stack): C4.1 complete-downtime window records on gatherer ticks (#13257) - #13295
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 39 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b11b655e9b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const spans: DowntimePoolSpan[] = []; | ||
| let latest = -Infinity; | ||
| for (const intervals of perPool) { | ||
| const iv = covers(intervals, start) as WallInterval; |
There was a problem hiding this comment.
Account for every binding limit in the latest reopening
When a pool has multiple overlapping wall intervals, covers() selects only the first one, so latest ignores other limits that still block that pool. For example, a single pool with two already-walled windows resetting at +1h and +10h produces reopening.earliest = +10h but reopening.latest = +1h; reversing the window order changes the result. This publishes an inverted reopening range and an incorrect full-restoration bound in both the JSON product and ledger. Compute the bound from all relevant blocking intervals rather than the first covering window.
Useful? React with 👍 / 👎.
| describe("deriveDowntimeWindow", () => { | ||
| test("overlapping walls predict a window with the intersection range and named basis", () => { |
There was a problem hiding this comment.
Add generated coverage for the downtime interval model
This suite contains only hand-written examples, although the new engine has union/intersection, maximal-window, and input-order invariants. AGENTS.md requires “property tests” where code has invariants and “model-based tests” where a model exists; acceptance examples alone do not satisfy that requirement. Add generated pool/window combinations checked against an independent interval-set oracle, including overlapping limits within a pool and permutation invariance—the current examples miss the order-dependent reopening calculation.
AGENTS.md reference: AGENTS.md:L37-L39
Useful? React with 👍 / 👎.
) Publish downtime_window prediction records on gatherer ticks, in the C4 design's record format (doc/2026-11-13T15-12-00Z_design_ reporting-architecture-event-driven/c4-forecasting-design.md §1/§7, landed by PR #13268): appended to quota-predictions.jsonl beside the forecast product and mirrored into the Turso ledger under the C4 source "quota-prediction". src/quota-downtime.ts derives each record from the tick's Stage-3 forecast product (#12695): per-pool wall intervals [wall, reset) intersected across every routing pool (canonical provider id); earliest = the last member wall, latest = the earliest member reset; basis since_last_reset, named with its detail; the §4 range rendering stored at issuance; supersedes linked from the log's tail. Honesty per §1 and #13257 criterion 3: providers the forecast cannot project publish insufficient_history with a named reason (and veto a no-window verdict); an overlap no member reset bounds is an honesty state, not an unbounded prediction; a defensible no-window tick publishes no record — absence is the scored no-prediction signal. First methodology entry c4-meth:1 recorded in c4-methodology-log.jsonl (§6). Acceptance: criteria 1 (records published on gatherer ticks) and 3 (honesty state) of #13257. Criterion 2 (scoring per §3 in the accuracy ledger) is the next slice; the mirrored records are its input. Tests: src/quota-downtime.test.ts (15 tests: record shape, intersection range, in-progress windows, union within a provider, disjoint overlaps, honesty states, supersedes, §4 rendering, ledger mirror), mutation-checked; the gather-quota integration test now also asserts the tick appends the downtime record. Oracle: the C4 design §1/§7 over the #12695 forecast product.
b11b655 to
6569d04
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6569d04a58
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const bounded = overlaps.filter((o) => Number.isFinite(o.end)); | ||
| if (bounded.length > 0) { | ||
| return bounded.map((o) => { |
There was a problem hiding this comment.
Preserve the honesty state for an unbounded trailing overlap
When a tick contains both a finite complete-downtime interval and a later unbounded one, this early return silently drops the unbounded interval and bypasses the insufficient_history branch below. For example, a single provider with windows [+1h, +2h) and [+3h, Infinity) publishes only the first prediction, without disclosing that another all-walled interval cannot be bounded. Preserve an honesty record for the unbounded overlap even when finite predictions also exist, so the JSONL log and ledger distinguish an unbounded forecast from no prediction.
Useful? React with 👍 / 👎.
| const records = deriveDowntimeWindowRecords(forecast, previous); | ||
| if (records.length) { | ||
| await mkdir(dirname(predictionsPath), { recursive: true }); | ||
| await appendFile(predictionsPath, records.map((r) => JSON.stringify(r)).join("\n") + "\n", "utf8"); |
There was a problem hiding this comment.
Separate new records from a torn log tail before appending
If a previous append was interrupted before its terminating newline, the parser skips the torn final line, but this append concatenates the next tick's first record directly onto that fragment. The resulting line is invalid JSON, so the first new prediction is also lost from the readable log and cannot become a subsequent supersedes target; for the usual single-record tick, this loses the entire tick locally even though the ledger write proceeds. Repair or delimit an unterminated tail before appending new records so the intended torn-log recovery preserves the next prediction.
Useful? React with 👍 / 👎.
| ): C4PredictionRecord[] { | ||
| const issuedAt = forecast.generatedAt; | ||
| const issuedMs = Date.parse(issuedAt); | ||
| const providerIds = Object.keys(forecast.pools).sort(); |
There was a problem hiding this comment.
Restrict the downtime intersection to enabled routing providers
The forecast's provider keys are not exclusively routing pools: gather-quota.ts:264–278 explicitly requests quota for disabled doors, and collectRuns() retains those results in the entries passed to buildQuotaForecast(). In the checked .opencode/opencode.jsonc:350–363, _commandcode and deepseek are disabled but still explicitly gathered. Consequently, when every enabled routing provider is walled but one of these disabled providers has a no-wall-before-reset forecast, its empty down-set makes this function return no downtime prediction, even though that provider cannot serve as a fallback. Pass the enabled routing set into the derivation and intersect only those providers, while retaining disabled-provider measurements in the broader forecast product.
Useful? React with 👍 / 👎.
What
Implements acceptance criteria 1 and 3 of #13257 (C4.1, component of #9572): complete-downtime window predictions, published on gatherer ticks in the C4 design's record format.
Design conformance note: the C4 design (
c4-forecasting-design.md, PR #13268) landed while this slice was in flight. This PR was reconciled to it before merge — record schema (§1), storage (thequota-predictions.jsonllog + Turso mirror under sourcequota-prediction), basis enum, honesty states, and §7's derivation are all the design's, not a parallel shape.pm-stack/aggregator/src/quota-downtime.ts(new): pure derivation over one tick's Stage-3 forecast product (quota-forecast.json, impl(quota-plane): stage-3 S1 — forecast product: per-tick quota-forecast from the analytics pace math #12695). Per-pool wall intervals[wall, reset)are intersected across every routing pool (canonical provider id; a provider is down while any of its pool rows' windows is down). Each record:earliest= the last member wall,latest= the earliest member reset (the first reopening),basis=since_last_resetwith detail,inputs(series/samples/span,adjustments: []), the §4renderedstring produced at issuance by the shared formatter (renderPredictionRange: duration / day / calendar forms, America/Chicago),methodology_version: c4-meth:1, and thesupersedeslink.pm-stack/aggregator/c4-methodology-log.jsonl(new): the §6 methodology log's first entry, versioned into the repo with the code change that implements it.pm-stack/aggregator/scripts/gather-quota.ts: fail-soft block after the forecast publication — derives the tick's records, appends them toquota-predictions.jsonlbeside the forecast product (path overridable viaQUOTA_PREDICTIONS_PATH), and mirrors them into the ledger via the existing forecast Turso sink. The supersedes chain reads the log's tail (fail-soft). A null forecast derives nothing; previous records stand and age with the previous forecast. Advisory only: no placement path reads these records.src/quota-downtime.test.ts(15 tests) plus a new assertion block intest/gather-quota.test.tsproving the tick appends the downtime record beside the forecast product.Honesty rules (§1, criterion 3)
insufficient-historywindows) can only add downtime, so a known overlap still publishes aspredictedwith the unknown providers named in the basis detail — but unknowns veto a no-window verdict: no known overlap + any unknown provider publishes aninsufficient_historyrecord with a named reason, never a silent absence and never an invented range.Verification (laptop route)
bun test src/quota-downtime.test.ts— 15 pass / 0 fail.every→some) fails 9 of 15 tests; restored, all green.bun test test/gather-quota.test.ts src/quota-forecast.test.ts src/quota-forecast-accuracy.test.ts— 38 pass / 0 fail.bunx tsc --noEmit— 0 errors (worktreenode_modulessymlinked from the primary checkout; a bare worktree lacks the bun type definitions).Remaining on #13257
Criterion 2 — scoring downtime windows per §3 (start/end error, interval overlap) in the accuracy ledger — is the next slice; the records mirrored here are its input. The issue stays open.
Refs #13257, #9572.